package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.QusetionBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.GETANSWER)
public class PostGetAnswer extends BaseAsyPost {

    public String type,user_id;
    public PostGetAnswer(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostGetAnswerInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostGetAnswerInfo info = new PostGetAnswerInfo();

            info.code = object.optString("code");

            JSONArray array = object.optJSONArray("data");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    QusetionBean qusetionBean = new QusetionBean();
                    qusetionBean.setId(jsonObject.optString("id"));
                    qusetionBean.setTitle(jsonObject.optString("title"));
                    qusetionBean.setPicurl(jsonObject.optString("picurl"));
                    qusetionBean.setGrand(jsonObject.optString("grand"));
                    qusetionBean.setType(jsonObject.optString("type"));

                    qusetionBean.setFormat(jsonObject.optString("format"));
                    qusetionBean.setOptionA(jsonObject.optString("optionA"));
                    qusetionBean.setOptionB(jsonObject.optString("optionB"));
                    qusetionBean.setOptionC(jsonObject.optString("optionC"));
                    qusetionBean.setOptionD(jsonObject.optString("optionD"));

                    qusetionBean.setOptionE(jsonObject.optString("optionE"));
                    qusetionBean.setOptionApic(jsonObject.optString("optionApic"));
                    qusetionBean.setOptionBpic(jsonObject.optString("optionBpic"));
                    qusetionBean.setOptionCpic(jsonObject.optString("optionCpic"));
                    qusetionBean.setOptionDpic(jsonObject.optString("optionDpic"));
                    qusetionBean.setOptionEpic(jsonObject.optString("optionEpic"));
                    qusetionBean.setAnswer(jsonObject.optString("answer"));
                    info.questionList.add(qusetionBean);

                }
            }


            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostGetAnswerInfo {

        public String code, message;
        public ArrayList<QusetionBean> questionList = new ArrayList<>();

    }

}
